package edu.washington.math.sage;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintStream;

import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
/*AUTHORS:
#*****************************************************************************
#       Copyright (C) 2009-2010 Kevin Stueve kstueve@uw.edu
#
#  Distributed under the terms of the GNU General Public License (GPL)
#                  http://www.gnu.org/licenses/
#*****************************************************************************
*/
//Resources: This class is heavily based on the ButtonPanel class in Kevin Stueve's CircuitEngine (http://sage.math.washington.edu/home/kstueve/CircuitEngine/index.html)
public final class ButtonPanel extends JPanel{
  private FlowLayout fl;
	PrintStream myPrintStream;
	//reference: http://mathworld.wolfram.com/ReuleauxTriangle.html
  static final String[] buttonNames = {"Square","Rectangle","Circle","Ellipse","Polygon","Reuleaux Triangle"};
  public ButtonPanel(final PyPhysSimGUIPanel parentGuiPanel) {
    super();
    fl=new FlowLayout();
    myPrintStream=System.out;
    this.setLayout(fl);
    this.add(new JLabel("Shape: "));
    JComboBox componentList = new JComboBox(buttonNames);
    this.add(componentList);
    componentList.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
        JComboBox cb = (JComboBox)e.getSource();
        String componentName = (String)cb.getSelectedItem();
    	myPrintStream.println("BUTTON_PRESSED "+componentName.replaceAll(" ", ""));
      }
    });
    componentList.setSelectedIndex(0);
    ButtonGroup pausePlayGroup = new ButtonGroup();
    JToggleButton pauseButton = new JToggleButton("Pause");
    JToggleButton playButton = new JToggleButton("Play");
    pausePlayGroup.add(pauseButton);
    pauseButton.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
    	  myPrintStream.println("BUTTON_PRESSED Pause");
      }
    });
    playButton.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
    	  myPrintStream.println("BUTTON_PRESSED Play");
      }
    });
    pausePlayGroup.add(playButton);
    pauseButton.doClick();
    JPanel pausePlayPanel = new JPanel();
    pausePlayPanel.setBackground(Color.green);
    this.add(pausePlayPanel);
    pausePlayPanel.add(pauseButton);
    pausePlayPanel.add(playButton);
    ButtonGroup modeGroup = new ButtonGroup();
    JToggleButton moveButton = new JToggleButton("Move");
    JToggleButton createButton = new JToggleButton("Create");
    JToggleButton deleteButton = new JToggleButton("Delete");
    JToggleButton examineButton = new JToggleButton("Examine");
    modeGroup.add(moveButton);
    modeGroup.add(createButton);
    modeGroup.add(deleteButton);
    modeGroup.add(examineButton);
    moveButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
      	  myPrintStream.println("BUTTON_PRESSED Move");
        }
      });
    createButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
      	  myPrintStream.println("BUTTON_PRESSED Create");
        }
      });
    deleteButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
      	  myPrintStream.println("BUTTON_PRESSED Delete");
        }
      });
    examineButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
      	  myPrintStream.println("BUTTON_PRESSED Examine");
        }
      });
    createButton.doClick();
    JPanel modePanel = new JPanel();
    modePanel.setBackground(Color.blue);
    this.add(modePanel);
    modePanel.add(moveButton);
    modePanel.add(createButton);
    modePanel.add(deleteButton);
    modePanel.add(examineButton);
  }

}